package com.itcast.googleplay.holder;

import com.itcast.googleplay.R;
import com.itcast.googleplay.bean.AppInfo;
import com.itcast.googleplay.http.HttpApi;
import com.itcast.googleplay.utils.UIUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.text.format.Formatter;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

public class AppHolder extends BaseHolder<AppInfo>{
	private AppInfo appInfo;
	private ImageView ivIcon;
	private TextView tvName,tvSize,tvDes;
	private RatingBar ratingBar;
	private DisplayImageOptions options;

	@Override
	public void initData() {
		options = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.ic_default)
			.showImageForEmptyUri(R.drawable.ic_default)
			.showImageOnFail(R.drawable.ic_default)
			.cacheInMemory(true)
			.cacheOnDisk(true)
			.considerExifParams(true)//是否允许让图片反转
			.build();//设置圆角弧度
		
		appInfo = getData();
		tvName.setText(appInfo.name);
		ratingBar.setRating(appInfo.stars);
		tvSize.setText(Formatter.formatFileSize(UIUtils.getContext(), appInfo.size));
		tvDes.setText(appInfo.des);
		
		ImageLoader.getInstance().displayImage(HttpApi.IMAGEURL+appInfo.getIconUrl(), ivIcon, options);
	}

	@Override
	public View initView() {
		View view = UIUtils.inflate(R.layout.list_item_app);
		ivIcon = (ImageView) view.findViewById(R.id.iv_icon);
		tvName = (TextView) view.findViewById(R.id.tv_name);
		ratingBar = (RatingBar) view.findViewById(R.id.ratingbar);
		tvSize = (TextView) view.findViewById(R.id.tv_size);
		tvDes = (TextView) view.findViewById(R.id.tv_des);
		return view;
	}
}
